package com.qidian.buy.product.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qidian.buy.entity.Item;
import com.qidian.buy.product.service.IItemCatService;
import com.qidian.buy.product.service.IItemService;
import com.qidian.buy.util.Constant;
import com.qidian.buy.util.pojo.BuyResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 商品表 前端控制器
 * </p>
 *
 * @author 戴着假发的程序员
 * @since 2023-07-05
 */
@RestController
@CrossOrigin
@RequestMapping("/buy/item")
public class ItemController {
    @Autowired
    private IItemService itemService;
    @GetMapping("/query")
    public List<Item> query(){
        return itemService.list();
    }

    @GetMapping(value = "/list",produces = Constant.CONTENT_TYPE_JSON_UTF8) //"application/json;charset=utf-8";
    public BuyResult list(@RequestParam(defaultValue = "1")int page, @RequestParam(defaultValue = "10")int limit){
        return itemService.queryByPage(page,limit);
    }
    @PostMapping("/save")
    public BuyResult save(@RequestBody Item item){
        return itemService.saveItem(item);
    }

    @GetMapping("/get")
    public BuyResult get(Long itemId){
        return itemService.queryItemAndDescById(itemId);
    }

    @PostMapping("/edit")
    public BuyResult edit(@RequestBody Item item){
        return itemService.updateItem(item);
    }

    @GetMapping("/delete")
    public BuyResult delete(Long itemId){
        return itemService.deleteItem(itemId);
    };
}
